package com.example.android.BluetoothChat.util.factory;

import android.R;
import android.app.AlertDialog;
import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;

import com.example.android.BluetoothChat.activity.PlayerListActivity;
import com.example.android.BluetoothChat.bean.Game;
import com.example.android.BluetoothChat.bean.Player;

public class ComponentFactory {

	public static final AlertDialog createNewGameRequestAlertBox(Context parContext, Player parPlayer, Game parGame){
		AlertDialog.Builder builder = new AlertDialog.Builder(parContext);
		builder.setMessage(parPlayer.getName() + " wants you to join him to play " + parGame.getName() + ". Do you want to join him ?")
		       .setCancelable(false)
		       .setPositiveButton("Yes", new DialogInterface.OnClickListener() {
		           public void onClick(DialogInterface dialog, int id) {
		        	   dialog.cancel();
		           }
		       })
		       .setNegativeButton("No", new DialogInterface.OnClickListener() {
		           public void onClick(DialogInterface dialog, int id) {
		                dialog.cancel();
		           }
		       });
    	
		return builder.create();
	}
	
	public static Notification createNewGameRequestNotification(Context parContext, Player parPlayer, Game parGame){
		//Get a reference to the NotificationManager:
		String ns = Context.NOTIFICATION_SERVICE;
		NotificationManager mNotificationManager = (NotificationManager) parContext.getSystemService(ns);
		
		//Instantiate the Notification:
		int icon = R.drawable.stat_notify_more;
		CharSequence tickerText = "New game request";
		long when = System.currentTimeMillis();
		Notification notification = new Notification(icon, tickerText, when);
		
		//Define the notification's message and PendingIntent:
		CharSequence contentTitle = "New game request";
		CharSequence contentText = parPlayer.getName() + " wants you to join him to play " + parGame.getName() + ". Do you want to join him ?";
		Intent notificationIntent = new Intent(parContext, PlayerListActivity.class);
		PendingIntent contentIntent = PendingIntent.getActivity(parContext, 0, notificationIntent, 0);

		notification.setLatestEventInfo(parContext, contentTitle, contentText, contentIntent);
		
		mNotificationManager.notify(1, notification);
		return notification;
	}
	
	
	public static Notification createNewPlayerNotification(Context parContext, Player parPlayer){
		//Get a reference to the NotificationManager:
		String ns = Context.NOTIFICATION_SERVICE;
		NotificationManager mNotificationManager = (NotificationManager) parContext.getSystemService(ns);
		
		//Instantiate the Notification:
		int icon = R.drawable.stat_notify_more;
		CharSequence tickerText = "New player found";
		long when = System.currentTimeMillis();
		Notification notification = new Notification(icon, tickerText, when);
		
		//Define the notification's message and PendingIntent:
		CharSequence contentTitle = "New player found";
		CharSequence contentText = " A new player has been found : " + parPlayer.getName() + ". Do you want to play with him ?";
		Intent notificationIntent = new Intent(parContext, PlayerListActivity.class);
		PendingIntent contentIntent = PendingIntent.getActivity(parContext, 0, notificationIntent, 0);

		notification.setLatestEventInfo(parContext, contentTitle, contentText, contentIntent);
		
		mNotificationManager.notify(1, notification);
		return notification;
	}
	
	
}
